home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
The World of Computer Software.iso
/
tcsel003.zip
/
SCRT.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1992-10-16
|
4KB
|
157 lines
unit scrt;
{
by Trevor J Carlsen
PO Box 568
Port Hedland
Western Australia 6721
Phone -
Voice: 61 91 732026
Data : 61 91 732569
This little unit is intended to replace the crt unit in programs that do
not require many of that units functions. As a result the resulting .exe
code is much smaller.
Released into the public domain 1989
}
interface
function Keypressed: boolean;
{ Returns true if there is a keystroke waiting in the key buffer }
procedure ClrScr;
{ Clears the screen and homes the cursor }
procedure ClrKey;
{ Flushes the keystroke buffer }
function KeyWord : word;
inline ($B4/$00/ {mov ah,0}
$CD/$16); {int 16h}
{ Waits for a keypress and returns a word containing the scancode and }
{ ascii code for the keypressed }
function ExtKey(var k : char; var s : byte): boolean;
{ Gets next keystroke from the keystroke buffer. If it was an extended key }
{ (ie. function key etc.) returns true and k contains the scan code. If a }
{ normal key then returns false and k contains the character and s the scan}
{ code }
function ReadKey: char;
{ Gets next keystroke from the buffer. If extended key returns #0 }
function NextKey: char;
{ Flushes the keystroke buffer and then returns the next key as ReadKey }
function PeekKey: char;
{ Peeks at the next keypress in the buffer without removing it }
procedure Delay(s : word);
{ Machine independent delay loop for s seconds }
procedure GotoXY(x,y : byte);
{ Moves the cursor to X, y coordinates }
{ -------------------------------------------------------------------------- }
implementation
uses dos;
var
head : word absolute $0040:$001A;
tail : word absolute $0040:$001C;
time : longint absolute $0040:$006C;
regs : registers;
function Keypressed: boolean;
begin
Keypressed := (tail <> head);
end;
procedure ClrScr; { 25 line display only }
begin
inline($B4/$06/$B0/$19/$B7/$07/$B5/$00/$B1/$00/$B6/$19/$B2/$4F/
$CD/$10/$B4/$02/$B7/$00/$B2/$00/$B6/$00/$CD/$10);
end;
procedure ClrKey;
begin
head := tail;
end;
function ExtKey(var k : char; var s : byte): boolean;
var
keycode : word;
al : byte;
ah : byte;
begin
ExtKey := false;
repeat
keycode := KeyWord;
al := lo(keycode);
ah := hi(keycode);
if al = 0 then begin
ExtKey := true;
al := ah;
end;
until al <> 0;
k := chr(al);
s := al;
end; {ExtKey}
function ReadKey : char;
var
Key : byte;
begin
Key := lo(KeyWord);
ReadKey := char(Key);
end;
function NextKey : char;
begin
tail := head;
NextKey := ReadKey;
end;
function PeekKey : char;
begin
PeekKey := char(Mem[$40:head]);
end;
procedure delay(s : word);
var
start : longint;
finished : boolean;
begin
start := time;
repeat
if time < start then { midnight rollover occurred during the period }
dec(start,$1800B0);
finished := (time > (start + s * 18.2));
until finished;
end;
procedure gotoXY(x,y : byte);
begin
with regs do begin
ah := $02;
bh := 0;
dh := pred(y);
dl := pred(x);
intr($10,regs);
end; { with }
end; { gotoXY }
end.